import '../public/index'
import url from '../data/url'
import request from '../data/request'
import {header} from '../data/config'

import {bank as valid_bank} from '../data/validate'

const base = url.base,
  search = '/project/stop/detail.json',
  save = '/project/stop/doModify.json'

// 页面标题
const title = '停止时间配置',
  action = '清除';

const app = {
  ysNoTime: null,
  id: null,
  init() {
    this.getTime()
  },
  getTime: () => {
    $.ajax({
      type: "POST",
      url: base + search,
      dataType: "json",
      headers: {
        myToken: Cookies.get('myToken')
      },
    }).then(res => {
      app.ysNoTime = res.object.ysNoTime
      app.id = res.object.id
      app.showStopTime(app.ysNoTime)
      app.bindEvent()
    })
  },
  showStopTime(time) {
    $('#stop-time').text(time)
  },
  btnRemove: () => {
    let ajaxData = {
      id: this.id,
      ysNoTime: ''
    }
    $.ajax({
      type: "POST",
      url: base + save,
      dataType: "json",
      data: ajaxData,
      headers: {
        myToken: Cookies.get('myToken')
      },
    }).then(res => {
      console.log('response:', res)
    })
  },
  bindEvent: () => {
    $('#time-modify').on('click', e => {
      e.preventDefault()
      location.href = './modify.html?id=' + app.id
    })

    $('#time-remove').on('click', e => {
      e.preventDefault()
      let ajaxData = {
        id: app.id,
        ysNoTime: ''
      }
      $.ajax({
        type: "POST",
        url: base + save,
        dataType: "json",
        data: ajaxData,
        headers: {
          myToken: Cookies.get('myToken')
        },
      }).then(res => {
        if (res.code == 0) {
          window.location.reload()
        }
      })
    })
  }
}

app.init()
